import {AlertController, IonicPage, NavController, NavParams} from "ionic-angular";
import {Component} from "@angular/core";
import {HttpClient} from "@angular/common/http";
import {AppUrl} from "../../../../app/app.general";



@IonicPage()
@Component({
  selector: "page-busifood-tablecontentset",
  templateUrl: "busifood-tablecontentset.html",
})


export class BusifoodTableContentSetPage {

  tableset: string = 'tableset';
  private tablename: string;
  private tableSite: string;
  private tablesize: string;
  private tableplace: string;
  private floorid: string;
  tableData = {
    floorid: '',
    tablename: '',
    tableid:0,
    tablesize: '',
    outflag: '0',
  };

  private callBack: any;

  constructor(public navCtrl: NavController, public navParams: NavParams, public http: HttpClient,private alertCtrl:AlertController) {
    this.tableset = this.navParams.get('tableset');
    this.tablename = this.navParams.get('tablename');
    this.tableSite = this.navParams.get('tableSite');
    this.tablesize = this.navParams.get('tablesize');
    this.tableplace = this.navParams.get('tableplace');
    this.floorid = this.navParams.get('floorid');
    this.callBack = this.navParams.get('callback');
  }
  showAlert(message) {
    let alert = this.alertCtrl.create({
      title: '警告',
      subTitle: message,
      buttons: ['确定']
    });
    alert.present();
  }

  submitClick() {
    console.info('提交全部数据' +this.tableData.tablename+this.tableData.outflag+this.tableData.tablesize+this.tableData.floorid);
    this.tableData.floorid=this.floorid;
    if(this.tableData.tablename == null){
      this.showAlert("请输入餐台名");
      return;
    }else if(this.tableData.tablename.trim() == ''){
      this.showAlert("请输入正确的餐台名");
      return;
    }
    if(this.tableData.outflag == null){
      this.showAlert("请选择是否外送");
      return;
    }else if(this.tableData.outflag.trim() == ''){
      this.showAlert("请选择是否外送");
      return;
    }
    if(this.tableData.tablesize == null){
      this.showAlert("请选择餐台大小");
      return;
    }else if(this.tableData.tablesize.trim() == ''){
      this.showAlert("请选择餐台大小");
      return;
    }
    this.http.post(AppUrl.table.addtable,{tableno:this.tableData.tablename,floorid:this.floorid,
    outflag:this.tableData.outflag,status:'0',rid:'',del:0,tablesize:this.tableData.tablesize}).subscribe(data=>{
      let temp:any=data;
      this.tableData.tableid=temp.data[0];
      this.callBack(this.tableData).then(() => {
        this.navCtrl.pop();
      });
    });
  }
}
